class Solution {
public:
    int edgeScore(vector<int>& edges)
    {
        long long ans = -1;
        unordered_map<long long, long long> hash;
        for (int i = 0; i < edges.size(); i++)
        {
            hash[edges[i]] += i;
            if (hash[edges[i]] == hash[ans]) ans = min(ans, (long long)edges[i]);
            else ans = hash[edges[i]] > hash[ans] ? edges[i] : ans;
        }
        return ans;
    }
};